#!/bin/bash
# Version 0.0.1
#time=`date "+%Y-%m-%d-%H"`

num1=`tail -10000 /var/log/nginx/access.log|awk '$9 == 200 {print $1}'|sort|uniq|wc -l`
num2=`tail -10000 /var/log/nginx/access.log|awk '$9 == 200 {print $1}'|wc -l`
num3=`echo "scale=5; $num1/$num2*10000" |bc `

num=${num3%.*}

# Getting parameters:
while getopts "w:c:h" OPT;do
case $OPT in
"w")warning=$OPTARG;;
"c")critical=$OPTARG;;
"h")help;;
esac
done

#Comparing the result and setting the correct level:
if [[ $num -lt $critical ]]; then
	msg="CRITICAL"
	status=2
else if [[ $num -lt $warning ]]; then
	msg="WARNING"
	status=1
else
	msg="OKOKOK"
	status=0
    fi
fi

#Printing the results:
echo "$msg - Uniq ip on the last 10000 requests Num $num"

exit $status
